<#assign pageTitle = "${teacher.name }" />
<#assign pageKeywords = pageTitle />
<#assign pageDescription = pageTitle />
<#assign channelId = 5 />
<#assign pageHeader>
</#assign>
<#assign pageContent>
	<div class="body-wrap">
		<div class="teacher-view-header">
			<div class="content-wrap">
				<div class="crumbs pd-20">
					<i class="layui-icon layui-icon-home"></i>
					<a href="/" target="_blank">首页</a>
					<span class="sep">/</span>
					<a href="/teacher/index.html" target="_blank">专家</a>
					<span class="sep">/</span>
					详情
				</div>
				<div class="teacher-view-info">
					<div class="teacher-info-top">
						<div class="teacher-img">
							<#if teacher.avatar?? && teacher.avatar?string != '' >
								<img lay-src="${teacher.avatar }" alt="">
							<#else >
								<img src="/static/images/teacher/teacher-avatar-${teacher.sex}.png" alt="">
							</#if>
						</div>
						<div class="teacher-name">
							<h2>${teacher.name } ${starName!}</h2>
							<span class="subject-name">${subjectName!}</span>
							<div>
								${teacher.workUnit!} ${teacher.workDept!}
							</div>
							<div class="list-teacher-type">
								<#if teacher.tags??>
									<#assign tags = teacher.tags?split(',') />
									<#list tags as tag>
										<span>${tag}</span>
									</#list>
								</#if>
							</div>
							<div class="teacher-view-introduce">
								${teacher.intro}
							</div>
						</div>
					</div>
					<div class="teacher-viewCount"><i class="layui-icon layui-icon-fire"></i>人气：${teacher.viewCount!}</div>
				</div>
			</div>
		</div>
		<div class="layui-tab layui-tab-brief teacher-view-teb">
			<ul class="layui-tab-title">
				<#if courseCount gt 0>
					<li onclick="getList(${teacher.id},'course', 1)" data-id="course">同步课(<span style="color: red">${courseCount!}</span>)</li>
				</#if>
				<#if proCount gt 0>
					<li onclick="getList(${teacher.id},'pro', 1)" data-id="pro">大师课(<span style="color: red">${proCount!}</span>)</li>
				</#if>
				<#if bookCount gt 0>
					<li onclick="getList(${teacher.id},'book', 1)" data-id="book">教材出版(<span style="color: red">${bookCount!}</span>)</li>
				</#if>
			</ul>
			<div class="layui-tab-content">
				<#if courseCount gt 0>
				<div class="layui-tab-item">
					<div class="content-wrap">
						<div class="course-list mb-20" id="course-list"></div>
					</div>
				</div>
				</#if>
				<#if proCount gt 0>
				<div class="layui-tab-item">
					<div class="content-wrap">
						<div class="articles-list mb-20" id="pro-list"></div>
					</div>
				</div>
				</#if>
				<#if bookCount gt 0>
				<div class="layui-tab-item">
					<div class="content-wrap">
						<div class="book-list-small mb-20" id="book-list"></div>
					</div>
				</div>
				</#if>
			</div>
		</div>
		<!-- 公共分页 开始  要换成ajax-->
		<div style="text-align: center;" class="paging" id="showPages"></div>
		<!-- 公共分页 结束 -->
	</div>
</#assign>
<#assign pageFooter>
	<script type="text/javascript" src="/static/js/page.js"></script>
</#assign>
<#include "../layouts/layout.ftl">
<script type="text/javascript">
	var teacherId =${teacher.id}
	var courseCount =${courseCount!}
	var proCount =${proCount!}
	var bookCount =${bookCount!}
	$(function () {
		var obj = $(".layui-tab-title").children(0);
		obj.click();
	})

	function getList(teacherId, type, page) {
		$.post("/teacher/get/list.json", {"teacherId": teacherId, "type": type, "page": page}, function (json) {
			console.log(json)
			if (json.code === 0) {
				var isEmpty = "<div class=\"data-null\">\n" +
						"<i class=\"icon-data-null\"></i>\n" +
						"<p>老师还没有创建内容哦，去看看其它吧</p>\n" +
						"</div>";
				var html = "";
				switch (type) {
					case "course":
						if (json.data.data.length > 0) {
							json.data.data.forEach(function (value, index) {
								html += '<div class="list-items">\n' +
										'<div class="list-item">\n' +
										'<div class="list-content">\n' +
										'<a href="/course/view/' + value.courseId + '.html" target="_blank" class="list-course-title">' + value.courseName + '</a>\n' +
										'<a href="/course/view/' + value.courseId + '.html" target="_blank" class="list-course-img">\n' +
										'<img src="' + value.cover + '" alt="">\n' +
										'<div class="hover-img"><span class="layui-icon layui-icon-play"></span> </div>\n' +
										'</a>\n' +
										'<div class="list-course-info"><span>' + value.intro + '</span></div>\n' +
										'<div class="list-course-price">￥' + value.price / 100 + '</div>\n' +
										'<div class="list-course-type">' + value.categoryName + '</div>\n' +
										'</div>\n' +
										'</div>\n' +
										'</div>'
							})
							pageShow("course", json.data.page, courseCount);
						} else {
							html = isEmpty;
						}
						$("#course-list").empty().append(html);
						break;
					case "pro":
						if (json.data.data.length > 0) {
							json.data.data.forEach(function (value, index) {
								html += '<div class="list-items">\n' +
										'<div class="list-item">\n' +
										'<div class="list-content">\n' +
										'<a href="/course/view/' + value.courseId + '.html" target="_blank" class="list-article-img"><img alt="" src="' + value.cover + '"></a>\n' +
										'<a href="/course/view/' + value.courseId + '.html" target="_blank" class="list-article-title">' + value.courseName + '</a>\n' +
										'<div class="list-article-info">' + value.intro + '</div>\n' +
										'<div class="list-article-price">￥' + value.price / 100 + '</div>\n' +
										'<div class="list-article-type">' + value.categoryName + '</div>\n' +
										'</div>\n' +
										'</div>\n' +
										'</div>'
							})
							pageShow("pro", json.data.page, proCount);
						} else {
							html = isEmpty;
						}
						$("#pro-list").empty().append(html);
						break;
					case "book":
						if (json.data.data.length > 0) {
							json.data.data.forEach(function (value, index) {
								html += '<div class="list-items">\n' +
										'<div class="list-item">\n' +
										'<div class="list-content">\n' +
										'<a href="/book/view/' + value.id + '.html" target="_blank" class="list-book-img">\n' +
										'<img src="' + value.cover + '" alt="">\n' +
										'</a>\n' +
										'<div class="list-book-content">\n' +
										'<a href="/book/view/' + value.id + '.html" target="_blank" class="list-course-title">' + value.title + '</a>\n' +
										'<div class="list-book-info">' + value.intro + '</div>\n' +
										'<div class="list-book-price">￥' + value.price / 100 + '</div>\n' +
										'<div class="list-book-type">' + value.categoryName + '</div>\n' +
										'</div>\n' +
										'</div>\n' +
										'</div>\n' +
										'</div>'
							})
							pageShow("book", json.data.page, bookCount);
						} else {
							html = isEmpty;
						}
						$("#book-list").empty().append(html);
						break;
					default:
						return false;
				}
			}
		})
	}

	function pageShow(type, page, count) {
		var form = layui.form;
		layui.laypage.render({
			elem: 'showPages'
			, theme: '#1E9FFF'
			, limit: page.pageSize
			, curr: page.currentPage
			, count: count //数据总数，从服务端得到
			, jump: function (obj, first) {
				//首次不执行
				if (!first) {
					getList(teacherId, type, obj.curr);
					return false
				}
			}
		});

	}
</script>